﻿using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.Imginforsa
{
    public class ImgInforQueryCommandHandler : IRequestHandler<ImgInforQueryCommand, APIResult<List<ImgInfor>>>
    {
        public ImgInforQueryCommandHandler(IBaseRepository<ImgInfor> imginforRepository)
        {
            ImginforRepository = imginforRepository;
        }

        public IBaseRepository<ImgInfor> ImginforRepository { get; }

        public async Task<APIResult<List<ImgInfor>>> Handle(ImgInforQueryCommand request, CancellationToken cancellationToken)
        {
            var path = ImginforRepository.GetAll().Where(a => a.Name == request.name && a.Productuins == request.Productuins);
            return new APIResult<List<ImgInfor>>
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path.ToList()
            };
        }
    }
}
